<template>
  <en-table-layout
    :tableData="tableData"
    :loading="loading"
  >
    <div slot="toolbar" class="inner-toolbar">
      <div class="toolbar-btns">
        <el-button type="primary" @click="handleLeader()">审核</el-button>
        <el-button type="danger" @click="handleLeader()">删除</el-button>
      </div>
      <div class="toolbar-search">
        <en-table-search
          @search="searchEvent"
          @advancedSearch="advancedSearchEvent"
          advanced
          advancedWidth="465"
          placeholder="请输入关键字">
          <template slot="advanced-content">
                <el-form ref="advancedForm" :model="advancedForm"  label-width="80px">              
                  <el-form-item label="审核状态" class="toolbar-input" prop="op_status">
                    <el-select v-model="advancedForm.op_status" placeholder="请选择审核状态" class="select-get" clearable>
                      <el-option label="休息中" :value="0"></el-option>
                      <el-option label="营业中" :value="1"></el-option>
                    </el-select>
                  </el-form-item>
                <el-form-item label="所在地区" class="toolbar-input" prop="region">
                  <en-region-picker
                    :api="MixinRegionApi"
                    :default="advancedForm.areas"
                    @changed="(object) => { advancedForm.region = object.last_id }"
                    class="select-get"
                    clearable
                  ></en-region-picker>
                </el-form-item>
                <el-form-item label="店铺类型" class="toolbar-input" prop="leader_type">
                  <el-select v-model="advancedForm.leader_type" class="select-get" clearable>
                    <el-option label="虚拟团长" :value="0"></el-option>
                    <el-option label="真实团长" :value="1"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="申请时间" class="toolbar-input" prop="status">
                  <el-date-picker
                    v-model="value2"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right">
                  </el-date-picker>
                </el-form-item>
                </el-form>
          </template>
        </en-table-search>
      </div>
    </div>

    <!-- 列表渲染 -->
    <template slot="table-columns">
      <el-table-column type="selection" min-width="50"></el-table-column>
      <el-table-column prop="leader_id" min-width="80" label="申请编号" />
      <el-table-column prop="leader_name" min-width="100" label="审核状态" />
      <el-table-column prop="leader_mobile" min-width="150" label="团长姓名" />
      <el-table-column prop="audit_status" min-width="150" label="审核状态" />
      <el-table-column label="团长类型" min-width="80">
        <template slot-scope="scope">
          <span>{{scope.row.leader_type==1?"真实团长":"虚拟团长"}}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="level" min-width="80" label="团长等级"/> -->
      <el-table-column label="联系电话">
        <template slot-scope="scope">
          <span>{{scope.row.status==1?"启用":"禁用"}}</span>
        </template>
      </el-table-column>
      <el-table-column label="小区名称" >
        <template slot-scope="scope">
          <span>{{scope.row.op_status==1?"营业中":"休息中"}}</span>
        </template>
        </el-table-column>
      <el-table-column prop="member_id" min-width="80" label="联系地址" />
      <el-table-column prop="cell_name" min-width="100" label="门店名称" />
      <el-table-column prop="province" min-width="100" label="店铺类型" />
      <el-table-column min-width="100" label="申请时间">
        <template
          slot-scope="scope"
        >{{ scope.row.update_time | unixToDate("yyyy-MM-dd hh:mm:ss") }}</template>
      </el-table-column>
        <el-table-column prop="site_name" min-width="100" label="申请理由" />
        <el-table-column prop="site_name" min-width="100" label="审核人员" />
      <el-table-column min-width="100" label="审核时间">
        <template slot-scope="scope">{{ scope.row.add_time | unixToDate("yyyy-MM-dd hh:mm:ss") }}</template>
      </el-table-column>
      <el-table-column prop="site_name" min-width="100" label="审核备注" />

      <el-table-column min-width="100" label="创建时间">
        <template slot-scope="scope">{{ scope.row.add_time | unixToDate("yyyy-MM-dd hh:mm:ss") }}</template>
      </el-table-column>
      <el-table-column prop="creater_name" min-width="100" label="创建人" />
        <el-table-column min-width="100" label="修改时间">
        <template slot-scope="scope">{{ scope.row.add_time | unixToDate("yyyy-MM-dd hh:mm:ss") }}</template>
      </el-table-column>
      <el-table-column prop="creater_name" min-width="100" label="修改人" />
    </template>
    <!-- 分页列表 -->
      <el-pagination
        v-if="tableData"
        slot="pagination"
        @size-change="handlePageSizeChange"
        @current-change="handlePageCurrentChange"
        :current-page="tableData.page_no"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="tableData.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="tableData.data_total">
      </el-pagination>
  </en-table-layout>
</template>

<script>
  import * as API_goods from '@/api/goods'
  import * as API_LEADER from '@/api/leader';

  export default {
    name: 'leaderAudit',
    data() {
      return {
        /** 列表loading状态 */
        loading: false,

        /** 列表参数 */
        params: {
          page_no: 1,
          page_size: 10
        },

        /** 商品列表数据 */
        tableData: '',

        value2: '',
        /** 高级搜索数据 */
        advancedForm: {
          k1: '',
          k2: '',
          k3: '',
          k4: ''
        }
      }
    },
    mounted() {
      this.GET_GoodsList()
    },

    methods: {

      /** 分页大小发生改变 */
      handlePageSizeChange(size) {
        this.params.page_size = size
        this.GET_GoodsList()
      },

      /** 分页页数发生改变 */
      handlePageCurrentChange(page) {
        this.params.page_no = page
        this.GET_GoodsList()
      },

      /** 改变优先级 */
      handleModifyPriority(row) {
        API_goods.modifyPriority(row.goods_id, row.priority).then(_ => {
          this.loading = false
        }).catch()
      },

      /** 搜索事件触发 */
      searchEvent(data) {
        this.params = {
          ...this.params,
          keyword: data
        }
        this.params.page_no = 1
        Object.keys(this.advancedForm).forEach(key => delete this.params[key])
        this.GET_GoodsList()
      },

      /** 高级搜索事件触发 */
      advancedSearchEvent() {
        this.params = {
          ...this.params,
          ...this.advancedForm
        }
        delete this.params.keyword
        this.params.page_no = 1
        this.GET_GoodsList()
      },

      /** 高级搜索中 分类选择组件值发生改变 */
      categoryChanged(data) {
        this.advancedForm.category_path = data.category_path || ''
      },

      GET_GoodsList() {
        this.loading = true
        API_goods.getGoodsList(this.params).then(response => {
          this.loading = false
          this.tableData = response
          console.log(this.tableData)
        }).catch(() => (this.loading = false))
      }
    }
  }
</script>

<style type="text/scss" lang="scss" scoped>
//顶部工具栏样式
.inner-toolbar{
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
  }

//基本信息和站点信息
.infomation {
  font-size: 15px;
  font-weight: bold;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid;
}

//地图和所在地区组件
/deep/ .app-address {
  width: 100% !important;
  height: 32px;
  .app-address-title {
    padding: 0 20px 0 15px;
    height: 32px;
    line-height: 32px;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
  }
}

//高德地图
.map {
  position: relative;
  width: 500px;
  .map-search {
    position: absolute;
    top: 15px;
    right: 15px;
    padding: 5px 10px;
    width: 300px;
    line-height: 22px;
    border: none;
    border-radius: 4px;
    outline: none;
    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.15);
    overflow: hidden;
  }
}

//设置对话框两个按钮居中
.footer {
  display: flex;
  justify-content: center;
}

//设置高德地图输入框位置和尺寸
.map .map-search {
  width: 200px;
  left: 60px;
}

.select-get{
  width: 100%;
}

//设置对话框内的输入框宽度
.select-type {
  width: 300px;
}

//设置远程搜索(关联用户)左右对齐
.mobile {
  float: right;
}
</style>

<style type="text/scss" lang="scss">
.toolbar-input .el-form-item__label {
  font-weight: normal;
}

//显示高德地图输入框提示
.amap-sug-result {
  z-index: 9999;
}
</style>